package controllers;

import java.util.Map;
import java.util.Map.Entry;

import models.User;
import play.mvc.Controller;
import play.mvc.Http;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
public class Users extends Controller {

	public static void login(String username, String password) {
		
	}

	public static void logout() {
		
	}

//	public static void register(String mail,
//			String password,
//			String passwordConfirmation,
//			String phone,
//			String address, 
//			String name) {
	public static void register(){
		String text = params.allSimple().get("body");
		/*for(Entry<String, String> e : params.allSimple().entrySet()) {
			System.out.println(e.getKey() + ": " + e.getValue());
		}*/
		
		User user = new Gson().fromJson(text, User.class);
		
		System.out.println("name: " + user.name);
		System.out.println("mail: " + user.mail);
		
//		User user = new User();
//		user.mail = mail;
//		user.password = password;
//		user.name = name;
//		user.address = address;
//		user.phone = phone;
		
		if (user.save() != null) {
			renderJSON("{\"response\": \"cenas\"}");
		} else {
			renderJSON("{\"response\": \"nok\"}");
		}

	}

}
